<!DOCTYPE HTML>
<html>
<head>
	<title>Hello world</title>
</head>
<body>
<p>Price of item : <?php echo $_POST["item"];?></p>

<?php
/*
 $options = array(
    'options' => array(
          'min_range' => -1,
          //'max_range' => 999,               
          )
);
*/
function checknumber($i){
	
	if (is_numeric($i) && $i >= 0 && $i == round($i)) {
  		return TRUE;	
	}else{
		return FALSE;
	}
}
	if(checknumber($_POST[txt1000]) && 
   		checknumber($_POST[txt500]) && 
   		checknumber($_POST[txt100]) &&
  		checknumber($_POST[txt20]) &&
  		checknumber($_POST[txt10]) &&
   		checknumber($_POST[txt5]) &&
   		checknumber($_POST[txt1])
   ) {
   
     
   
  $b1 = $_POST[txt1000]*1000 ."<br>";
  $b2 = $_POST[txt500]*500 ."<br>";
  $b3 = $_POST[txt100]*100 ."<br>";
  $b4 = $_POST[txt20]*20 ."<br>";
  $b5 = $_POST[txt10]*10 ."<br>";
  $b6 = $_POST[txt5]*5 ."<br>";
  $b7 = $_POST[txt1]*1 ."<br>"; 
  $total = $b1+$b2+$b3+$b4+$b5+$b6+$b7;
  $change = $total - $_POST["item"] ;
  
  if ($total>=$change && $change>0) {
      
  	echo "pay :" .$total. "<br>" ."change :" .$change. "<br>";	

/*<p>change : <?php echo $change = $total - $_POST["item"] ;?></p> */

	while($change!=0){
		if (floor($change/1000)>0) {
			$rs = floor($change/1000);
			$change = $change -($rs*1000);
			echo "bank 1000 > "  .$rs ."<br>";
		
		}elseif(floor($change/500)>0) {
			$rs = floor($change/500);
			$change = $change-($rs*500);
			echo "bank 500 > " .$rs ."<br>";
			
		}elseif(floor($change/100)>0) {
			$rs = floor($change/100);
			$change = $change-($rs*100);
			
			echo "bank 100 > " .$rs ."<br>";
		}else if(floor($change/20)>0){
			$rs = floor($change/20);
			$change = $change-($rs*20);
			
			echo "bank 20 > " .$rs ."<br>";
		}else if(floor($change/10)>0){
			$rs = floor($change/10);
			$change = $change-($rs*10);
			
			echo "coin 10 > " .$rs ."<br>";
		}else if(floor($change/5)>0){
			$rs= floor($change/5);
			$change = $change-($rs*5);
			
			echo "coin 5 > " .$rs ."<br>";	
		}else if(floor($change/1)>0){
			$rs = floor($change/1);
			$change = $change-($rs*1);
			
			echo "coin 1 > ".$rs ."<br>";
		}else{
			echo "error.";
		}
	}
	}else{
		echo "Please pay more money.";
	}
}else{
	echo "reject.";
}
?>
</body>
</html>